<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="typesseq-strings.html" />
<link rel="prev" href="typesseq.html" />
<link rel="parent" href="typesseq.html" />
<link rel="next" href="typesseq-strings.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>3.6.1 String Methods </title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="3.6 sequence Types "
  href="typesseq.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="3.6 sequence Types "
  href="typesseq.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="3.6.2 string Formatting Operations"
  href="typesseq-strings.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="typesseq.html">3.6 Sequence Types </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="typesseq.html">3.6 Sequence Types </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="typesseq-strings.html">3.6.2 String Formatting Operations</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h2><a name="SECTION005610000000000000000"></a><a name="string-methods"></a>
<br>
3.6.1 String Methods 
</h2>
<a id='l2h-233' xml:id='l2h-233'></a>
<p>
These are the string methods which both 8-bit strings and Unicode
objects support:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-234' xml:id='l2h-234' class="method">capitalize</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return a copy of the string with only its first character capitalized.

<p>
For 8-bit strings, this method is locale-dependent.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-235' xml:id='l2h-235' class="method">center</tt></b>(</nobr></td>
  <td><var>width</var><big>[</big><var>, fillchar</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return centered in a string of length <var>width</var>. Padding is done
using the specified <var>fillchar</var> (default is a space).

<span class="versionnote">Changed in version 2.4:
Support for the <var>fillchar</var> argument.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-236' xml:id='l2h-236' class="method">count</tt></b>(</nobr></td>
  <td><var>sub</var><big>[</big><var>, start</var><big>[</big><var>, end</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return the number of occurrences of substring <var>sub</var> in string
S<code>[<var>start</var>:<var>end</var>]</code>.  Optional arguments <var>start</var> and
<var>end</var> are interpreted as in slice notation.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-237' xml:id='l2h-237' class="method">decode</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>encoding</var><big>[</big><var>, errors</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Decodes the string using the codec registered for <var>encoding</var>.
<var>encoding</var> defaults to the default string encoding.  <var>errors</var>
may be given to set a different error handling scheme.  The default is
<code>'strict'</code>, meaning that encoding errors raise
<tt class="exception">UnicodeError</tt>.  Other possible values are <code>'ignore'</code>,
<code>'replace'</code> and any other name registered via
<tt class="function">codecs.register_error</tt>, see section&nbsp;<a href="codec-base-classes.html#codec-base-classes">4.8.1</a>.

<span class="versionnote">New in version 2.2.</span>

<span class="versionnote">Changed in version 2.3:
Support for other error handling schemes added.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-238' xml:id='l2h-238' class="method">encode</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>encoding</var><big>[</big><var>,errors</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return an encoded version of the string.  Default encoding is the current
default string encoding.  <var>errors</var> may be given to set a different
error handling scheme.  The default for <var>errors</var> is
<code>'strict'</code>, meaning that encoding errors raise a
<tt class="exception">UnicodeError</tt>.  Other possible values are <code>'ignore'</code>,
<code>'replace'</code>, <code>'xmlcharrefreplace'</code>, <code>'backslashreplace'</code>
and any other name registered via <tt class="function">codecs.register_error</tt>,
see section&nbsp;<a href="codec-base-classes.html#codec-base-classes">4.8.1</a>.
For a list of possible encodings, see section&nbsp;<a href="standard-encodings.html#standard-encodings">4.8.3</a>.

<span class="versionnote">New in version 2.0.</span>

<span class="versionnote">Changed in version 2.3:
Support for <code>'xmlcharrefreplace'</code> and
<code>'backslashreplace'</code> and other error handling schemes added.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-239' xml:id='l2h-239' class="method">endswith</tt></b>(</nobr></td>
  <td><var>suffix</var><big>[</big><var>, start</var><big>[</big><var>, end</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return <code>True</code> if the string ends with the specified <var>suffix</var>,
otherwise return <code>False</code>.  <var>suffix</var> can also be a tuple of
suffixes to look for.  With optional <var>start</var>, test beginning at
that position.  With optional <var>end</var>, stop comparing at that position.

<p>

<span class="versionnote">Changed in version 2.5:
Accept tuples as <var>suffix</var>.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-240' xml:id='l2h-240' class="method">expandtabs</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>tabsize</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return a copy of the string where all tab characters are expanded
using spaces.  If <var>tabsize</var> is not given, a tab size of <code>8</code>
characters is assumed.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-241' xml:id='l2h-241' class="method">find</tt></b>(</nobr></td>
  <td><var>sub</var><big>[</big><var>, start</var><big>[</big><var>, end</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return the lowest index in the string where substring <var>sub</var> is
found, such that <var>sub</var> is contained in the range [<var>start</var>,
<var>end</var>].  Optional arguments <var>start</var> and <var>end</var> are
interpreted as in slice notation.  Return <code>-1</code> if <var>sub</var> is
not found.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-242' xml:id='l2h-242' class="method">index</tt></b>(</nobr></td>
  <td><var>sub</var><big>[</big><var>, start</var><big>[</big><var>, end</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Like <tt class="method">find()</tt>, but raise <tt class="exception">ValueError</tt> when the
substring is not found.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-243' xml:id='l2h-243' class="method">isalnum</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return true if all characters in the string are alphanumeric and there
is at least one character, false otherwise.

<p>
For 8-bit strings, this method is locale-dependent.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-244' xml:id='l2h-244' class="method">isalpha</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return true if all characters in the string are alphabetic and there
is at least one character, false otherwise.

<p>
For 8-bit strings, this method is locale-dependent.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-245' xml:id='l2h-245' class="method">isdigit</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return true if all characters in the string are digits and there
is at least one character, false otherwise.

<p>
For 8-bit strings, this method is locale-dependent.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-246' xml:id='l2h-246' class="method">islower</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return true if all cased characters in the string are lowercase and
there is at least one cased character, false otherwise.

<p>
For 8-bit strings, this method is locale-dependent.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-247' xml:id='l2h-247' class="method">isspace</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return true if there are only whitespace characters in the string and
there is at least one character, false otherwise.

<p>
For 8-bit strings, this method is locale-dependent.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-248' xml:id='l2h-248' class="method">istitle</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return true if the string is a titlecased string and there is at least one
character, for example uppercase characters may only follow uncased
characters and lowercase characters only cased ones.  Return false
otherwise.

<p>
For 8-bit strings, this method is locale-dependent.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-249' xml:id='l2h-249' class="method">isupper</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return true if all cased characters in the string are uppercase and
there is at least one cased character, false otherwise.

<p>
For 8-bit strings, this method is locale-dependent.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-250' xml:id='l2h-250' class="method">join</tt></b>(</nobr></td>
  <td><var>seq</var>)</td></tr></table></dt>
<dd>
Return a string which is the concatenation of the strings in the
sequence <var>seq</var>.  The separator between elements is the string
providing this method.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-251' xml:id='l2h-251' class="method">ljust</tt></b>(</nobr></td>
  <td><var>width</var><big>[</big><var>, fillchar</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return the string left justified in a string of length <var>width</var>.
Padding is done using the specified <var>fillchar</var> (default is a
space).  The original string is returned if
<var>width</var> is less than <code>len(<var>s</var>)</code>.

<span class="versionnote">Changed in version 2.4:
Support for the <var>fillchar</var> argument.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-252' xml:id='l2h-252' class="method">lower</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return a copy of the string converted to lowercase.

<p>
For 8-bit strings, this method is locale-dependent.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-253' xml:id='l2h-253' class="method">lstrip</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>chars</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return a copy of the string with leading characters removed.  The
<var>chars</var> argument is a string specifying the set of characters
to be removed.  If omitted or <code>None</code>, the <var>chars</var> argument
defaults to removing whitespace.  The <var>chars</var> argument is not
a prefix; rather, all combinations of its values are stripped:
<div class="verbatim"><pre>
    &gt;&gt;&gt; '   spacious   '.lstrip()
    'spacious   '
    &gt;&gt;&gt; 'www.example.com'.lstrip('cmowz.')
    'example.com'
</pre></div>

<span class="versionnote">Changed in version 2.2.2:
Support for the <var>chars</var> argument.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-254' xml:id='l2h-254' class="method">partition</tt></b>(</nobr></td>
  <td><var>sep</var>)</td></tr></table></dt>
<dd>
Split the string at the first occurrence of <var>sep</var>, and return
a 3-tuple containing the part before the separator, the separator
itself, and the part after the separator.  If the separator is not
found, return a 3-tuple containing the string itself, followed by
two empty strings.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-255' xml:id='l2h-255' class="method">replace</tt></b>(</nobr></td>
  <td><var>old, new</var><big>[</big><var>, count</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return a copy of the string with all occurrences of substring
<var>old</var> replaced by <var>new</var>.  If the optional argument
<var>count</var> is given, only the first <var>count</var> occurrences are
replaced.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-256' xml:id='l2h-256' class="method">rfind</tt></b>(</nobr></td>
  <td><var>sub </var><big>[</big><var>,start </var><big>[</big><var>,end</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return the highest index in the string where substring <var>sub</var> is
found, such that <var>sub</var> is contained within s[start,end].  Optional
arguments <var>start</var> and <var>end</var> are interpreted as in slice
notation.  Return <code>-1</code> on failure.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-257' xml:id='l2h-257' class="method">rindex</tt></b>(</nobr></td>
  <td><var>sub</var><big>[</big><var>, start</var><big>[</big><var>, end</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Like <tt class="method">rfind()</tt> but raises <tt class="exception">ValueError</tt> when the
substring <var>sub</var> is not found.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-258' xml:id='l2h-258' class="method">rjust</tt></b>(</nobr></td>
  <td><var>width</var><big>[</big><var>, fillchar</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return the string right justified in a string of length <var>width</var>.
Padding is done using the specified <var>fillchar</var> (default is a space).
The original string is returned if
<var>width</var> is less than <code>len(<var>s</var>)</code>.

<span class="versionnote">Changed in version 2.4:
Support for the <var>fillchar</var> argument.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-259' xml:id='l2h-259' class="method">rpartition</tt></b>(</nobr></td>
  <td><var>sep</var>)</td></tr></table></dt>
<dd>
Split the string at the last occurrence of <var>sep</var>, and return
a 3-tuple containing the part before the separator, the separator
itself, and the part after the separator.  If the separator is not
found, return a 3-tuple containing two empty strings, followed by
the string itself.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-260' xml:id='l2h-260' class="method">rsplit</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>sep </var><big>[</big><var>,maxsplit</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return a list of the words in the string, using <var>sep</var> as the
delimiter string.  If <var>maxsplit</var> is given, at most <var>maxsplit</var>
splits are done, the <em>rightmost</em> ones.  If <var>sep</var> is not specified
or <code>None</code>, any whitespace string is a separator.  Except for splitting
from the right, <tt class="method">rsplit()</tt> behaves like <tt class="method">split()</tt> which
is described in detail below.

<span class="versionnote">New in version 2.4.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-261' xml:id='l2h-261' class="method">rstrip</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>chars</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return a copy of the string with trailing characters removed.  The
<var>chars</var> argument is a string specifying the set of characters
to be removed.  If omitted or <code>None</code>, the <var>chars</var> argument
defaults to removing whitespace.  The <var>chars</var> argument is not
a suffix; rather, all combinations of its values are stripped:
<div class="verbatim"><pre>
    &gt;&gt;&gt; '   spacious   '.rstrip()
    '   spacious'
    &gt;&gt;&gt; 'mississippi'.rstrip('ipz')
    'mississ'
</pre></div>

<span class="versionnote">Changed in version 2.2.2:
Support for the <var>chars</var> argument.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-262' xml:id='l2h-262' class="method">split</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>sep </var><big>[</big><var>,maxsplit</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return a list of the words in the string, using <var>sep</var> as the
delimiter string.  If <var>maxsplit</var> is given, at most <var>maxsplit</var>
splits are done. (thus, the list will have at most <code><var>maxsplit</var>+1</code>
elements).  If <var>maxsplit</var> is not specified, then there
is no limit on the number of splits (all possible splits are made).
Consecutive delimiters are not grouped together and are
deemed to delimit empty strings (for example, "<tt class="samp">'1„2'.split(',')</tt>"returns "<tt class="samp">['1', '', '2']</tt>").  The <var>sep</var> argument may consist of
multiple characters (for example, "<tt class="samp">'1, 2, 3'.split(', ')</tt>" returns
"<tt class="samp">['1', '2', '3']</tt>").  Splitting an empty string with a specified
separator returns "<tt class="samp">['']</tt>".

<p>
If <var>sep</var> is not specified or is <code>None</code>, a different splitting
algorithm is applied.  First, whitespace characters (spaces, tabs,
newlines, returns, and formfeeds) are stripped from both ends.  Then,
words are separated by arbitrary length strings of whitespace
characters. Consecutive whitespace delimiters are treated as a single
delimiter ("<tt class="samp">'1  2  3'.split()</tt>" returns "<tt class="samp">['1', '2', '3']</tt>").
Splitting an empty string or a string consisting of just whitespace
returns an empty list.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-263' xml:id='l2h-263' class="method">splitlines</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>keepends</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return a list of the lines in the string, breaking at line
boundaries.  Line breaks are not included in the resulting list unless
<var>keepends</var> is given and true.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-264' xml:id='l2h-264' class="method">startswith</tt></b>(</nobr></td>
  <td><var>prefix</var><big>[</big><var>,
                                       start</var><big>[</big><var>, end</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return <code>True</code> if string starts with the <var>prefix</var>, otherwise
return <code>False</code>.  <var>prefix</var> can also be a tuple of
prefixes to look for.  With optional <var>start</var>, test string beginning at
that position.  With optional <var>end</var>, stop comparing string at that
position.

<p>

<span class="versionnote">Changed in version 2.5:
Accept tuples as <var>prefix</var>.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-265' xml:id='l2h-265' class="method">strip</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>chars</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return a copy of the string with the leading and trailing characters
removed.  The <var>chars</var> argument is a string specifying the set of
characters to be removed.  If omitted or <code>None</code>, the <var>chars</var>
argument defaults to removing whitespace.  The <var>chars</var> argument is not
a prefix or suffix; rather, all combinations of its values are stripped:
<div class="verbatim"><pre>
    &gt;&gt;&gt; '   spacious   '.strip()
    'spacious'
    &gt;&gt;&gt; 'www.example.com'.strip('cmowz.')
    'example'
</pre></div>

<span class="versionnote">Changed in version 2.2.2:
Support for the <var>chars</var> argument.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-266' xml:id='l2h-266' class="method">swapcase</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return a copy of the string with uppercase characters converted to
lowercase and vice versa.

<p>
For 8-bit strings, this method is locale-dependent.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-267' xml:id='l2h-267' class="method">title</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return a titlecased version of the string: words start with uppercase
characters, all remaining cased characters are lowercase.

<p>
For 8-bit strings, this method is locale-dependent.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-268' xml:id='l2h-268' class="method">translate</tt></b>(</nobr></td>
  <td><var>table</var><big>[</big><var>, deletechars</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return a copy of the string where all characters occurring in the
optional argument <var>deletechars</var> are removed, and the remaining
characters have been mapped through the given translation table, which
must be a string of length 256.

<p>
You can use the <tt class="function">maketrans()</tt> helper function in the
<tt class="module"><a href="module-string.html">string</a></tt> module to create a translation table.

<p>
For Unicode objects, the <tt class="method">translate()</tt> method does not
accept the optional <var>deletechars</var> argument.  Instead, it
returns a copy of the <var>s</var> where all characters have been mapped
through the given translation table which must be a mapping of
Unicode ordinals to Unicode ordinals, Unicode strings or <code>None</code>.
Unmapped characters are left untouched. Characters mapped to <code>None</code>
are deleted.  Note, a more flexible approach is to create a custom
character mapping codec using the <tt class="module"><a href="module-codecs.html">codecs</a></tt> module (see
<tt class="module">encodings.cp1251</tt> for an example).      
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-269' xml:id='l2h-269' class="method">upper</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return a copy of the string converted to uppercase.

<p>
For 8-bit strings, this method is locale-dependent.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-270' xml:id='l2h-270' class="method">zfill</tt></b>(</nobr></td>
  <td><var>width</var>)</td></tr></table></dt>
<dd>
Return the numeric string left filled with zeros in a string
of length <var>width</var>. The original string is returned if
<var>width</var> is less than <code>len(<var>s</var>)</code>.

<span class="versionnote">New in version 2.2.2.</span>

</dl>

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="3.6 sequence Types "
  href="typesseq.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="3.6 sequence Types "
  href="typesseq.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="3.6.2 string Formatting Operations"
  href="typesseq-strings.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="typesseq.html">3.6 Sequence Types </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="typesseq.html">3.6 Sequence Types </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="typesseq-strings.html">3.6.2 String Formatting Operations</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
